package org.ring.server;

import org.ring.common.URL;
import org.ring.common.transport.ClientTransport;
import org.ring.common.transport.Connection;
import org.ring.common.transport.Message;
import org.ring.common.transport.TransportConfig;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;

/**
 * @since 2023-10-29 01:43
 */
public class ClientTransportTest {
    public static void main(String[] args) throws Exception {

        TransportConfig transportConfig = new TransportConfig();
        ClientTransport clientTransport = new ClientTransport(transportConfig);
        URL url = URL.valueOf("rpc://localhost:12300?timeout=1000");
        Connection connection = clientTransport.connect(url);

        int id = 0;

        while (true){
            Message message = new Message();
            message.setId(id++);
            message.setData("hi".getBytes(StandardCharsets.UTF_8));
            CompletableFuture responseFuture = connection.send(message);
            Message responseMessage = (Message)responseFuture.get();
            System.out.println("resp"+responseMessage);
        }
    }
}
